{extend name="template/base" /}
{block name="content"}
<!--select2样式 start -->
<link href="__LIB__/select2-4.0.3/dist/css/select2.min.css" rel="stylesheet" />
<div class="page-container">
    <br><br>
    {include file="form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            {tp:menu menu="delete,recyclebin" /}
            <!--<a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/hotel_accommodation/get_excel',$searchCondition)}" >excel导出</a>-->
            <a class="btn btn-primary radius mr-5" id="xuan" style=""  href="javascript:;" onclick="xuan()">excel导出</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l" id="ck" style="word-wrap: break-word;word-break: break-all;overflow: hidden;max-width: 500px;display: none">
        </span>
    </div>
    <div id="test">
        {include file="ajaxpage"}
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<!--select2 js 插件-->
<script type="text/javascript" src="__LIB__/select2-4.0.3/dist/js/select2.min.js"></script>
<script>
    //无刷新分页
    $(document).on('click','.pagination a',function (event) {
        var url = $(this).attr('href');
        $.ajax({
            type: 'get',
            url: url,
            success: function (data) {
                $('#test').empty();
                $('#test').html(data)
            }
        });
        return false;
    });

    //全选
    function checkAlls(e) {
        this.checked = $(e).is(':checked')
        $("#ck").css('display','inline')
        var ck_temp =  $("input:checked[name='id[]']");
        console.log('ck_temp',ck_temp)
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked;
        console.log('allChecked',allChecked)
        console.log('sonChecked',sonChecked)
        if (sonChecked && allChecked){
            var ck_arr = $("#ck").children();
            // $('#xuan').css('display','inline'); // 显示选择excel导出数据
            // $('#sou').css('display','none') ;// 隐藏部分或全部excel导出数据

            var radioData =  $("input:checked[name='id[]']");
            var ck = radioData.serializeArray();
            console.log('ck',ck)
            var len = ck.length;
                for(var i=0;i<len;i++){
                    var temp_to_ck = "#"+ck[i]['value']
                    if($(temp_to_ck).length ==0){
                        $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" style="padding: 2px 6px;margin: 2px" id='+ck[i]['value']+'>'+ck[i]['value']+'</span>')
                    }

                }
            ck.push({name: 'search',value: 'all'})
        }else{
            var len_ck = ck_temp.length;
            for(var y = 0;y < len_ck; y++){
                var temp_id = "#"+ck_temp[y]['value'];
                $(temp_id).remove()
            }
            // $('#xuan').css('display','none');
            // $('#sou').css('display','inline')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    }


    //全选
//    $('#checkAlls').bind("click", function () {
//        $("#ck").css('display','inline')
//        var ck_temp =  $("input:checked[name='id[]']");
//        console.log('ck_temp',ck_temp)
//        $("input[name='id[]']").prop("checked",this.checked);
//        var sonChecked = $("input[name='id[]']").prop('checked');
//        var allChecked = this.checked;
//        if (sonChecked && allChecked){
//            var ck_arr = $("#ck").children();
//            var ck_len = ck_arr.length
//            var dataArr = new Array
//            if(ck_len > 0){
//                for(var i = 0;i < ck_len;i++){
//                    dataArr.push(ck_arr[i].innerText)
//                }
//            }
//
//            $('#xuan').css('display','inline'); // 显示选择excel导出数据
//            $('#sou').css('display','none') ;// 隐藏部分或全部excel导出数据
//
//            var radioData =  $("input:checked[name='id[]']");
//            var ck = radioData.serializeArray();
//            console.log('ck',ck)
//            console.log('dataArr',dataArr)
//            var len = ck.length;
//            if(dataArr.length > 0){
//                for(var i=0;i<len;i++){
//                    for(var z = 0;z < dataArr.length; z++){
//                        if(dataArr[z] == ck[i]['value']){
//                            continue;
//                        }else{
//                            $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" style="padding: 2px 6px;margin: 2px" id='+ck[i]['value']+'>'+ck[i]['value']+'</span>')
//                        }
//                    }
//                }
//            }else{
//                for(var i=0;i<len;i++){
//                    $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" style="padding: 2px 6px;margin: 2px" id='+ck[i]['value']+'>'+ck[i]['value']+'</span>')
//                }
//            }
//
//            ck.push({name: 'search',value: 'all'})
//        }else{
//            var len_ck = ck_temp.length;
//            for(var y = 0;y < len_ck; y++){
//                var temp_id = "#"+ck_temp[y]['value'];
//                $(temp_id).remove()
//            }
//            $('#xuan').css('display','none');
//            $('#sou').css('display','inline')
//        }
//        // console.log('你点击我了')
//        // console.log('你是否被选中', this.checked)
//        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
//    });

    //单选
    function single(e) {
        $("#ck").css('display','inline')
        var ck = $(e).is(':checked')
        if(ck){
            var checked_len = $("input:checkbox:checked").length;
            var list_len = $("input[name='id[]']").length;
            if(list_len == checked_len){
                $('#checkAlls').prop('checked',true);
            }
            console.log('checked_len',checked_len)
            console.log('list_len',list_len)
            var val = $(e).val()
            $(e).prop('checked',true)
            $("#ck").append('<span class="btn btn-success radius" onclick="cancel(this)" id='+val+' style="padding: 2px 6px;margin: 2px">'+val+'</span>');
        }else{
            $('#checkAlls').prop('checked',false);
            var temp_id = "#"+$(e).val()
            $(temp_id).remove();
            $(e).attr('checked',false)
        }
    }

    function cancel(e) {
        var temp_id = "#"+$(e).attr('id')
        var temp_id_2 = "#ck_"+$(e).attr('id')
        $(temp_id_2).prop("checked",false);
        $(temp_id).remove();
    }

    function xuan() {
        var ck_arr = $("#ck").children();
        var ck_len = ck_arr.length
        var dataArr = new Array
        if(ck_len<=0){
            layer.msg('请进行勾选！', {
                time: 2000,
            });
            return true;
        }else{
            for(var i = 0;i < ck_len;i++){
                // dataArr.push({value:ck_arr[i].innerText})
                dataArr.push(ck_arr[i].innerText)
            }
            console.log('date',dataArr);
            $.ajax({
                type: 'post',
                url: '/admin/hotel_accommodation/get_excel',
                data: {ids:dataArr},
                success: function (res) {
                    if (res.code == 5){
                        // console.log('data', res);
                        location.href = res.msg; // 下载文件
                        // 删除文件
                        unclinkFile(res.msg)
                        layer.msg('导出数据成功');
                    } else {
                        layer_open('excel导出数据','/admin/pub/role/id/1')
                    }
                }
            });
        }
    }
    var  value = 1;
    setTimeout(unclinkFile,1200000,value); // 延迟20分钟1200000
    // 15分钟后删除文件-900000
    function unclinkFile(val) {
        console.log(val)
        setTimeout(function () {
            // 删除文件
            $.ajax({
                type: 'post',
                url: '/admin/order/del',
                data: {val:val},
                success: function (data) {
                    console.log('data', data)
                    if (data.code != 5) {
                        console.log('删除失败', data.msg)
                    }
                }
            })
        },120000,val); // 2分钟后执行
    }

</script>

<script>
    function settlement(id,val) {
        if (!id) {
            layer.msg('缺少id');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '/admin/hotel_accommodation/settlement',
            data: {id:id, val: val},
            success: function (ret) {
                if (ret.code == 1){
                    layer.msg(ret.msg);
                } else{
                    layer.msg(ret.msg);
                    location.reload(); // 刷新
                }
            }
        });
    }
</script>
<script>

        var hotel_room_type = $("#hotel_room_type").select2({
            language: "zh-CN", //设置 提示语言
            width: "100%", //设置下拉框的宽度
            theme: "classic"
        })
        {notempty name = "Request.param.hotel_room_type"}
        hotel_room_type.val("{$Request.param.hotel_room_type}").trigger("change");
        {/notempty}
</script>
{/block}